package com.laicunba.pojo;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.laicunba.annotation.MyColumn;
import com.laicunba.annotation.MyTable;
import com.laicunba.constant.GloabConstant;
import com.laicunba.util.StringUtil;

/**
 * 融资标的
 * 
 * @author why
 *
 */
@Component
@MyTable
public class FinancingTargetDO extends BaseDO implements Comparable<FinancingTargetDO> {
	private String name; // 标的名称
	private String code; // 标的代号
	@MyColumn(type = "int DEFAULT 0")
	private int period; // 周期天数
	private String interestWay; // 计息方式
	private String type; // SCB :随存宝
	private BigDecimal annualizedRates; // 年化利率 单位为 %,即 1表示 1%的收益
	private BigDecimal collectAmount; // 集资数量 (元)
	private BigDecimal finishAmount; // 完成数量(元)
	private BigDecimal limitAmount; // 限额数量(元)
	private BigDecimal minAmount; // 限额数量(元)
	/**
	 * new : 新创建, onsale: 可购买的 ,offsale :下架的, closed : 关闭的 ,checking : 核对中 ,
	 * archive:存档
	 */
	private String status;
	private Date beginDate;// 开标时间
	private Date endDate;// 结束时间

	@MyColumn(type = "text")
	private String description;

	@MyColumn(type = "int DEFAULT 0")
	private int bidCount; // 投标次数
	private String profitFlag;// 开始计息标记 TODAY:购买当天, TOMORROW : 购买第二天,
								// NEXT_WORK_DAY :下一个工作日(跳过周未,但其它法定假日这里不考虑)

	private String pics;// 图片的json信息
	private String picsDescription;
	private String cityAddress; // 城市地址
	private String targetMark; // 标签
	private String cashMark;
	private String draftInfo;// 汇票信息

	@MyColumn(type = "bool DEFAULT false")
	private boolean newInvestor; // 新手标

	private BigDecimal incrRate;//加息字段
	
	private String borrowerId;
	
	public void setBorrowerId(String borrowerId) {
		this.borrowerId = borrowerId;
	}
	public String getBorrowerId() {
		return borrowerId;
	}
	
	public void setIncrRate(BigDecimal incrRate) {
		this.incrRate = incrRate;
	}
	public BigDecimal getIncrRate() {
		return incrRate;
	}
	 
	
	public String getCityAddress() {
		return cityAddress;
	}

	public void setCityAddress(String cityAddress) {
		this.cityAddress = cityAddress;
	}

	public String getTargetMark() {
		return targetMark;
	}

	public void setTargetMark(String targetMark) {
		this.targetMark = targetMark;
	}

	public void setNewInvestor(boolean newInvestor) {
		this.newInvestor = newInvestor;
	}

	public boolean isNewInvestor() {
		return newInvestor;
	}

	public void setDraftInfo(String draftInfo) {
		this.draftInfo = draftInfo;
	}

	public String getDraftInfo() {
		return draftInfo;
	}

	public void setCashMark(String cashMark) {
		this.cashMark = cashMark;
	}

	public String getCashMark() {
		return cashMark;
	}

	public void setPicsDescription(String picsDescription) {
		this.picsDescription = picsDescription;
	}

	public String getPicsDescription() {
		if (StringUtil.isEmpty(picsDescription)) {
			return GloabConstant.DEFAULT_FINANCINGTARGET_PICS_DESCRIPTION;
		}
		return picsDescription;
	}

	public void setPics(String pics) {
		this.pics = pics;
	}

	public String getPics() {
		return pics;
	}

	public void setProfitFlag(String profitFlag) {
		this.profitFlag = profitFlag;
	}

	public String getProfitFlag() {
		return profitFlag;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getType() {
		return type;
	}

	public void setMinAmount(BigDecimal minAmount) {
		this.minAmount = minAmount;
	}

	public BigDecimal getMinAmount() {
		return minAmount;
	}

	public String getName() {
		return name;
	}

	public String getCode() {
		return code;
	}

	public int getPeriod() {
		return period;
	}

	public BigDecimal getAnnualizedRates() {
		return annualizedRates;
	}

	public BigDecimal getCollectAmount() {
		return collectAmount;
	}

	public void setCollectAmount(BigDecimal collectAmount) {
		this.collectAmount = collectAmount;
	}

	public BigDecimal getFinishAmount() {
		return finishAmount;
	}

	public BigDecimal getLimitAmount() {
		return limitAmount;
	}

	public String getStatus() {
		return status;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setPeriod(int period) {
		this.period = period;
	}

	public void setAnnualizedRates(BigDecimal annualizedRates) {
		this.annualizedRates = annualizedRates;
	}

	public void setFinishAmount(BigDecimal finishAmount) {
		this.finishAmount = finishAmount;
	}

	public void setLimitAmount(BigDecimal limitAmount) {
		this.limitAmount = limitAmount;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return StringUtil.isEmpty(description) ? GloabConstant.DEFAULT_FINANCINGTARGET_DESCRIPTION : description;
	}

	public String getInterestWay() {
		return StringUtil.isNotEmpty(borrowerId)?"T(成交日) +1":"SCB".equalsIgnoreCase(type) ? "T(成交日) +1" : "T(成交日) +0";
	}

	public void setInterestWay(String interestWay) {
		this.interestWay = interestWay;
	}

	public void setBidCount(int bidCount) {
		this.bidCount = bidCount;
	}

	public int getBidCount() {
		return bidCount;
	}

	@Override
	public int compareTo(FinancingTargetDO o) {
		int a = this.getFinishAmount().compareTo(this.getCollectAmount()) >= 0 ? 1 : 0;
		int b = o.getFinishAmount().compareTo(o.getCollectAmount()) >= 0 ? 1 : 0;
		if (a > b) {
			return 1;
		}
		if (a < b) {
			return -1;
		}

		if(a == 1 && b == 1) {
			return this.getGmtWrite().compareTo(o.getGmtWrite()) < 0 ? 1 : -1;
		}
		if (this.isNewInvestor()) {
			return -1;
		}

		if (o.isNewInvestor()) {
			return 1;
		}
		return this.getPeriod() > o.getPeriod() ? 1 : -1;
	}
}
